from flask import Blueprint, request, jsonify
from models import db, Events
from api.user import token_required  # 导入 JWT 验证装饰器

events_bp = Blueprint('events', __name__)

@events_bp.route('/events/submit', methods=['POST'])
@token_required  # 添加 JWT 验证
def submit_event(user_id):
    """提交举报事件"""
    try:
        data = request.json
        new_event = Events(
            reporter_id=user_id,  # 使用 JWT 中的 user_id
            reported_user_id=data.get('reported_user_id'),
            location=data.get('location'),
            violation_type=data.get('violation_type'),
            description=data.get('description'),
            scene_image=data.get('scene_image'),
            video=data.get('video')
        )
        db.session.add(new_event)
        db.session.commit()
        return jsonify({"message": "Event submitted successfully", "event_id": new_event.event_id}), 201
    except Exception as e:
        db.session.rollback()
        return jsonify({"error": str(e)}), 400

